package com.example.walletmodule.service.impl;

import com.example.walletmodule.mappers.UserDao;
import com.example.walletmodule.mappers.WalletDao;
import com.example.walletmodule.entity.UserEntity;
import com.example.walletmodule.entity.WalletEntity;
import com.example.walletmodule.service.UserService;
import com.example.walletmodule.util.SnowflakeUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;
import java.util.Date;


@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {

	@Resource
	private UserDao userDao;

	@Resource
	private WalletDao walletDao;

	public Integer addUser(UserEntity user) {
		user.setUserId(SnowflakeUtils.getId());
		// 新增用户信息
		int insert = userDao.insert(user);
		// 新增 用户钱包
		WalletEntity wallet = new WalletEntity();

		wallet.setWalletId(SnowflakeUtils.getId());
		wallet.setUserId(user.getUserId());
		wallet.setCrteTime(new Date());
		wallet.setUpdateTime(new Date());
		wallet.setWalletVersion(1);
		walletDao.insert(wallet);
		return insert;
	}

}